package pers.myutil.local.conversion.date;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 星座转换
 */
public class ConstellationConversion {

    private final static int[] dayArr = new int[] { 20, 19, 21, 20, 21, 22, 23, 23, 23, 24, 23, 22 };
    private final static Constellation[] constellationArr = {
         Constellation.AQUARIUS, Constellation.PISCES,
        Constellation.ARIES, Constellation.TAURUS,
        Constellation.GEMINI, Constellation.CANCER,
        Constellation.LEO, Constellation.VIRGO,
        Constellation.LIBRA, Constellation.SCORPIO,
        Constellation.SAGITTARIUS,Constellation.CAPRICORN
    };

    /**
     * 获取星座
     * @param date 时间
     * @return 星座
     */
    public static String getConstellation(Date date){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int day = calendar.get(Calendar.DATE);
        int month = calendar.get(Calendar.MONTH);
        return day < dayArr[month -1 ] ? constellationArr[month -1].getChineseName() : constellationArr[month].getChineseName();
    }
}
enum Constellation{

    ARIES(1,"白羊座"),
    TAURUS(2,"金牛座"),
    GEMINI(3,"双子座"),
    CANCER(4,"巨蟹座"),
    LEO(5,"狮子座"),
    VIRGO(6,"处女座"),
    LIBRA(7,"天秤座"),
    SCORPIO(8,"天蝎座"),
    SAGITTARIUS(9,"射手座"),
    CAPRICORN(10,"摩羯座"),
    AQUARIUS(11,"水瓶座"),
    PISCES(12,"双鱼座 ");

    private int code;
    private String chineseName;

    Constellation(int code, String chineseName) {
        this.code = code;
        this.chineseName = chineseName;
    }

    public int getCode() {
        return code;
    }

    public String getChineseName() {
        return chineseName;
    }
}
